В Python нет операции инкремента ++ как в си-подобных языках, поэтому используется x += 1. Однако запись ++x является валидным кодом (но не x++), так как это просто два унарных оператора сложения.
При применении унарного плюса у объекта вызывается магический метод __pos__, то есть запись ++x можно понять как x.__pos__().__pos__(). Зная это, можно реализовать класс, который будет представлять число и поддерживать поведение инкремента.
Код на картинке может показаться сначала немного сложным, но лучше проследить логику и понять работу метода __pos__. Если реализовать все остальные необходимо магические методы, то может получится полноценный класс числа, но в продакшне такие приколы лучше не писать.
В Python нет операции инкремента ++ как в си-подобных языках, поэтому используется x += 1. Однако запись ++x является валидным кодом (но не x++), так как это просто два унарных оператора сложения.
При применении унарного плюса у объекта вызывается магический метод __pos__, то есть запись ++x можно понять как x.__pos__().__pos__(). Зная это, можно реализовать класс, который будет представлять число и поддерживать поведение инкремента.
Код на картинке может показаться сначала немного сложным, но лучше проследить логику и понять работу метода __pos__. Если реализовать все остальные необходимо магические методы, то может получится полноценный класс числа, но в продакшне такие приколы лучше не писать.
At a time when the Indian stock market is peaking and has rallied immensely compared to global markets, there are companies that have not performed in the last 10 years. These are definitely a minor portion of the market considering there are hundreds of stocks that have turned multibagger since 2020. What went wrong with these stocks? Reasons vary from corporate governance, sectoral weakness, company specific and so on. But the more important question is, are these stocks worth buying?
Telegram auto-delete message, expiring invites, and more
elegram is updating its messaging app with options for auto-deleting messages, expiring invite links, and new unlimited groups, the company shared in a blog post. Much like Signal, Telegram received a burst of new users in the confusion over WhatsApp’s privacy policy and now the company is adopting features that were already part of its competitors’ apps, features which offer more security and privacy. Auto-deleting messages were already possible in Telegram’s encrypted Secret Chats, but this new update for iOS and Android adds the option to make messages disappear in any kind of chat. Auto-delete can be enabled inside of chats, and set to delete either 24 hours or seven days after messages are sent. Auto-delete won’t remove every message though; if a message was sent before the feature was turned on, it’ll stick around. Telegram’s competitors have had similar features: WhatsApp introduced a feature in 2020 and Signal has had disappearing messages since at least 2016.